#!/bin/bash

#bash <(echo "echo fuck");
DISTRO=$(cat /etc/*release  | grep "ID=" | grep -v "_ID=" | sed 's/^ID=//');
GITREPOURL="https://github.com/xenlism/minimalism.git";
GITTARURL="https://github.com/xenlism/minimalism/tarball/master";
TARGETURI="/tmp/xenlism-minimalism.tar.gz";

USRTHEMESDIR="/usr/share/themes";


echo "Welcome to Xenlism Minimalism Installation.";
echo "remark: ${DISTRO} linux";

function start {
	rm -rf /tmp/*minimalism*
	download_pkg
}

function install_pkg {
	cd /tmp;
	SOURCEDIR=$(ls -a /tmp | grep minimalism | grep -v "tar.gz")
	SOURCEDIR=$(echo "/tmp/${SOURCEDIR}");
	if [ -d $SOURCEDIR ]
	then
		cd "${SOURCEDIR}";
		if [ -d "${SOURCEDIR}/themes/" ]
		then
			echo "Info: Install Gnome / GTK  Theme."
			cd "${SOURCEDIR}/themes/"
  			sudo cp -r Xenlism-Minimalism "${USRTHEMESDIR}";
  			sudo find "${USRTHEMESDIR}" -type d -exec chmod 755 '{}' \;
  			sudo find "${USRTHEMESDIR}" -type f -exec chmod 644 '{}' \;
		else
			echo "Error; No Gnome / GTK theme source found."
		
		fi
	else 
		echo "Error: No Source Found"
		echo "No source directory.Please try again later."
	fi
}

function unpack_tar {
	if [ -f $TARGETURI ]
	then
		tar -zxvf $TARGETURI -C /tmp;
		install_pkg
	else
		echo "Error: Download error."
		echo "No tar Download file exits.Please try again later."
	fi
}

function download_pkg {
	echo "Info: Checking curl and wget."
	if which wget > /dev/null
	then
		echo "Info: Installation found wget."
		echo "Download source file from github."
		wget $GITTARURL -O $TARGETURI;
		unpack_tar
	elif which curl > /dev/null
	then
		echo "Info: Installation found wget."
		echo "Download source file from github."
		curl $GITTARURL -o $TARGETURI;
		unpack_tar
	else 
		echo "Error:Your System No wget and curl."
		echo "You have to wget or curl and try again later."
	fi
}

start

